package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2018/12/14 11:51
 * @description
 */
public class Code338 {
    public int[] countBits(int num) {
        int[] result = new int[num];
        for (int i = 0; i <= num; i++) {
            result[i] = getCount(Integer.toBinaryString(i));
        }
        return result;
    }

    private int getCount(String str) {
        str = str.replace("0", "");
        return str.length();
    }
}
